import re
import os
from bs4 import BeautifulSoup
from selenium import webdriver
import requests
import json
from fileUtils import FileHelper
 
def main():
    content2 = """  
                 <script type="text/javascript">  var cInfo = {
	  'bid':13001,'btitle':'TakeOnMe','cid':'07249b96f2f0c1cffd2684c0f8d84cab','ncid':'','pcid':'d6040291eed75a894e9992d0deec2354','ctitle':'018集','fs':['3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020214F25202029223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020224F21252122203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020234F21292324223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020244F21212820243E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020254F28262723223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020264F21292020233E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020274F22202228253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020284F21292129253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202020294F24242121293E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021204F26252125283E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021214F21282425293E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021224F21272429253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021234F25202621213E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021244F21262623213E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021254F26252720203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021264F22282925273E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021274F22212423213E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021284F22292122223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202021294F21202120213E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022204F27292525263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022214F21252728223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022224F22202629243E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022234F21222620273E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022244F22202627263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022254F21232826263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022264F27202322203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022274F21252427293E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022284F21222220273E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202022294F25222929243E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023204F21262824203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023214F25292523203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023224F21202529283E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023234F22262224253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023244F21212826223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023254F21262128293E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023264F21232024273E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023274F22222626203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023284F21242626253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202023294F27292826283E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024204F26292227253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024214F21232629253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024224F21252626203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024234F26272527263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024244F21292724253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024254F24242223243E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024264F21282325283E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024274F24272529263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024284F21232124263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202024294F22202022273E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025204F23242422203E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025214F21262427253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025224F22202525293E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025234F25222926273E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025244F23202927233E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025254F21232622263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025264F25272829283E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025274F22252122263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025284F21292123263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202025294F28272828283E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026204F21262421223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026214F23252224223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026224F28202727293E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026234F21232829253E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026244F29202426243E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026254F25262228233E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026264F27282620263E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026274F21242827213E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026284F21242627233E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202026294F24242124223E5A40573D2C21991','3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2021283F6A4F202027204F21242929273E5A40573D2C21991'],'fc':70,'zcount':19,'burl':'/comic/13001/','bs':0};  $((function(core,history){  core.init(pageConfig,cInfo);  history.add({'bid':cInfo.bid, 'cid': cInfo.cid,'bn': cInfo.btitle, 'cn': cInfo.ctitle, 'burl': cInfo.burl, 't': Math.floor(+new Date()/1000), 'p': core.currentPage}).bind('#history',true);  MHD.suggest.init({'view':true});   if(core.currentPage==1){MHD.viewStat(cInfo.bid,cInfo.cid);}  })(MHD.core,MHD.history));  </script>   
   
            """
    #comicName=re.compile(r"g_comic_name = \"(.*?)\"").findall(content2)
    # comicName=re.compile(r'\s*(.*?)\s*', re.S).findall(content2)
    # comicName = comicName[0]
    # chapter = re.compile(r'<li>(.*?)</li>', re.S).findall(content2)
    # print(chapter)

    print(len(os.listdir("../my/complete/刃牙道")))
    
    chapterUrl = re.compile(r'href="\s*(.*?)\s*" >', re.S).findall(content2)
    print(chapterUrl)
    # soup = BeautifulSoup(content2, 'html.parser')
    # 类名为xxx而且文本内容为hahaha的div
    # div = soup.find('div',class_='cartoon_online_border').find('ul').find_all('li')
    # print(div)
    # ul = div.get("ul")
    # print(ul)
    # for k in div:#,string='更多'
    #     val = k.find("a")
    #     print(k.find("a").find("title"))

    # for li in soup.select('li'):
        # print(li.get_text())
        # print(li.find('a').attrs['href'] )
 

def fileTest():
    # p = open("./hha/test.txt","w")
    os.makedirs("./download/刃牙死囚篇Ⅱ前传-东京复仇/No.1多利安/")

def htmlTest():
    f=open("X:\photos\photo_detail2.html",'rb')
    photoHtml=f.read().decode('utf-8')
    images =  re.compile(r'zoomfile="(.*?)"', re.S).findall(photoHtml)
    if len(images)==0:
        images =  re.compile(r'file="(.*?)"', re.S).findall(photoHtml)
    print(images)

def loadImgTest():
    
    targetPic = requests.session().get('https://www.98comic.com/g.php?de46f2f0419a769bf30e9d7e07f82b94/3F747D20283F3F7F7B3D737F7D797320283F443F23212627213F7173644F2020213F6A4F202021204F21212022293E5A40573D2C21991',timeout=(5,30))
    FileHelper.save_file("Z:/",'test.jpg',targetPic.content)
 
def urlTest():
     url = '/comic/13001/de46f2f0419a769bf30e9d7e07f82b94.html'
     print(url.split('/')[-1].replace('.html',''))

if __name__ == '__main__':
    # main()
    # fileTest()
    htmlTest()
    # urlTest()